{% extends "posts/show/layout.html" %}
{% load static %}
{% load posts %}
{% load battle %}
{% load text_filters %}

{% block post %}
    <div class="battle-header">
        {% if post.room %}
            <div class="battle-header-topic">
                {% include "rooms/widgets/room.html" with room=post.room type="post" %}
            </div>
        {% endif %}

        {% if post.deleted_at %}
            <div class="post-label">
                <span class="label label-type-deleted">
                    <span class="label-title">Удалённый пост</span>
                </span>
            </div>
        {% elif post.visibility == "draft" %}
            <div class="post-label">
                {% include "posts/widgets/draft_label.html" %}
            </div>
        {% endif %}
    </div>
    <div class="battle-title-main">
        <div class="block battle-title p-name" role="heading">
            <div class="battle-title-side-a">
                <div>{{ post.metadata.battle.sides.a.name | rutypography }}</div>
            </div>
            <div class="battle-title-vs">
                <div class="battle-title-vs-text">или</div>
            </div>
            <div class="battle-title-side-b">
                <div>{{ post.metadata.battle.sides.b.name | rutypography }}</div>
            </div>
        </div>

        <div class="post-actions-line">
            <span class="post-publicity-preferences">
                {% include "posts/widgets/publicity_preferences.html" with post=post %}
            </span>
            {% include "posts/widgets/post_actions_line.html" %}
        </div>
    </div>

    <div class="content">
        <div class="block post post-layout-block post-type-battle">
            <div class="post-upvote">
                <post-upvote :initial-upvotes="{{ post.upvotes }}"
                             :hours-to-retract-vote="{{settings.RETRACT_VOTE_IN_HOURS}}"
                             upvote-url="{% url "upvote_post" post.slug %}"
                             retract-vote-url="{% url "retract_post_vote" post.slug %}"
                             {% if is_voted %}
                                initial-is-voted
                                initial-upvote-timestamp={{upvoted_at}}
                             {% endif %}
                             {% if not me|can_upvote_post:post or upvote_disabled %}is-disabled{% endif %}>
                </post-upvote>
                <div class="clearfix20"></div>
            </div>

            <div class="text-body text-body-layout-notitle text-body-type-post e-content">
                {% render_post post %}
            </div>

            <div class="post-footer">
                <div class="p-author">
                    {% include "users/widgets/small.html" with user=post.author created_at=post.created_at %}
                </div>
            </div>
        </div>
    </div>

    {% if post.metadata.badges %}
        <div class="clearfix20"></div>
        <a class="post-badges post-badges-center" href="{% url "profile_badges" post.author.slug %}">
            {% include "badges/widgets/badges.html" with badges=post.metadata.badges %}
        </a>
    {% endif %}
{% endblock %}

{% block comments %}
    <div class="post-comments battle-comments" id="comments">
        <div class="comment-scroll-arrow-wrapper">
            <comment-scroll-arrow />
        </div>
        {% battle_stats post comments %}

        {% if me and me.is_active_membership %}
            <toggle
                url="{% url "toggle_post_subscription" post.slug %}"
                {% if subscription %}is-active-by-default{% endif %}
                class="post-comments-subscription"
            >
            подписка на аргументы
            </toggle>
        {% endif %}

        {% if post.is_commentable and not post.comment_count %}
            <div class="post-comments-title">
                <a href="#comments" class="post-comments-count">
                    Аргументируйте первым 👇
                </a>
            </div>
        {% endif %}

        {% if comments %}
            {% if post.is_commentable and me %}
                <reply-form
                    :reply-to="replyTo"
                    comment-order="{{ comment_order }}"
                    avatar-url="{{ me.get_avatar }}"
                    username="{{ me.full_name }}"
                    create-comment-url="{% url "create_comment" post.slug %}"
                ></reply-form>
            {% endif %}
            <div class="post-comments-list">
                {% include "comments/list.html" with comments=comments reply_form=reply_form type="battle" %}
            </div>
        {% endif %}

        {% if me and me.is_active_membership and post.is_commentable or me.is_moderator %}
            <div class="post-comments-form">
                {% include "comments/forms/battle.html" with post=post form=comment_form save_message="Отправить" %}
            </div>

            <div class="post-comments-rules">
                <strong>Этикет батлов:</strong>
                <ul>
                    <li>💣 Батл — это схватка двух крайностей. Мы пытаемся выделить аргументы каждой из сторон чтобы потом по ним составить свою картину мира. Рекомендуется избегать аргументов типа «каждый хорош для своего».</li>
                    <li>☝️ Один аргумент — один комментарий. Не делайте списков, так сложнее вести дискуссию и подсчитывать статистику.</li>
                    <li>😎 Можно топить как за одну, так и за обе стороны сразу. Просто выберите за кого вы при постинге.</li>
                    <li>💬 На аргументы можно отвечать. Реплаи никуда не засчитываются и нужны только для срача.</li>
                    <li>👮‍♀️ Авторам батлов нужно удалять повторы и комментарии не по формату.</li>
                </ul>
            </div>
        {% endif %}
    </div>

{% endblock %}
